import java.util.Scanner;

public class day230324 {
    // 连续最大和
    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            int[] array = new int[n];
            int sum = in.nextInt();
            int max = sum;
            for (int i = 1; i < n; i++) {
                int tmp = in.nextInt();
                // 求当前连续最大和
                // 如果加上之前的数更小, sum 就放弃之前的数
                sum = Math.max(sum + tmp, tmp);
                if (sum > max) {
                    max = sum;
                }
            }
            System.out.println(max);
        }
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 0;
        int max = Integer.MIN_VALUE;// 考虑负数的情况
        for (int i = 0; i < n; i++) {
            sum += scanner.nextInt();
            // 每次都比较最大值
            max = Math.max(sum,max);
            // sum 如果小于 0, 那就让它重0开始
            sum = (Math.max(sum, 0));
        }
        System.out.println(max);
    }


    // 统计回文
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();
        int count = 0;
        for (int i = 0; i <= str1.length(); i++) {
            // 遍历每个位置插入
            // new一个新的, 两个内容一样的StringBuffer / StringBuilder
            // String 没有 insert 方法
            // StringBuffer 是线程安全的, StringBuilder 不是线程安全的
            // 没有涉及线程安全的情况下, 用 StringBuilder 效率更高

            StringBuilder stringBuilder1 = new StringBuilder(str1);
            StringBuilder StringBuilder2 = new StringBuilder(stringBuilder1.insert(i, str2));
            // 将其中一个逆置, 与另一个比较来判断是否回文
            stringBuilder1.reverse();
            // StringBuffer / StingBuilder 类没有实现equals方法
            // 转为 String 再比较
            if (stringBuilder1.toString().equals(StringBuilder2.toString())) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();
        int count = 0;
        for (int i = 0; i <= str1.length(); i++) {
            StringBuilder stringBuilder = new StringBuilder(str1);
            // 遍历每个位置进行插入
            stringBuilder.insert(i,str2);
            if (func(stringBuilder)) {
                // 是回文串就++
                count++;
            }
        }
        System.out.println(count);
    }

    // 判断是否回文串
    public static boolean func(StringBuilder str) {
        int left = 0;
        int right = str.length() - 1;
        while (left < right) {
            if (str.charAt(left) != str.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
